﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Autenticazione.BusinessObject
{
    public class Descrizione
    {
        private int Tipo = -1;
        private long id;
        private string description;

        public long Id
        {
            get { return this.id;  }
            set { this.id = value; }
        }

        public string Description
        {
            get { return this.description; }
            set { this.description = value;  }
        }

        public Descrizione(int tipo)
        {
            this.Tipo = tipo;
        }

        public Descrizione(long id, string description)
        {
            this.Id = id;
            this.Description = description;
        }

        public List<Descrizione> GetDescriptions(int tipo)
        {
            SqlDataReader dr = null;
            List<Descrizione> descriptions = new List<Descrizione>();
            string strSQL = string.Format(@"select * from Descriptions where Type = {0} order by Description", tipo.ToString());
            DB.DB db = new DB.DB();

            dr = db.Reader(strSQL);

            if (dr == null)
                return descriptions;

            while (dr.Read())
                descriptions.Add(new Descrizione(long.Parse(dr["Id"].ToString()),
                                dr["Description"].ToString()));


            db.CloseConnection();

            return descriptions;
        }
    }
}